package k.dao.base;

import k.dto.Emp;
import k.dto.Event;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by sure
 */
@Component
public class EventDao {
    private String sql;
    @Autowired
    BaseDao baseDao;

    public void save(Event event){
        sql = "INSERT INTO `event` ( `event_title`, `event_content`, `lng`, `lat`, `event_address`, `phone`, `emp_id`, `emp_name`, `grid_id` , cdate) VALUES ('"+event.getEvent_title()+"','"+event.getEvent_content()+"','"+event.getLng()+"','"+event.getLat()+"','"+event.getEvent_address()+"','"+event.getPhone()+"','"+event.getEmp_id()+"','"+event.getEmp_name()+"','"+event.getGrid_id()+"',NOW())";
        baseDao.insert(sql,new Event());
    }
    /**
     * 查询最新的事件  sure
     * @return
     */
    public List<Event> queryEvent() {
        sql = "SELECT * FROM event ORDER BY cdate DESC LIMIT 1";
        return baseDao.query(sql, Event.class);

    }

    /**
     * 根据id查询事件表单详细信息
     *
     * @param id
     * @return
     */
    public Event getEventById(String id) {
        sql = "SELECT * FROM `event`  where event_id = " + id ;
        return baseDao.queryById(sql, Event.class);
    }

    public List<Event> queryAll (){
        sql = "SELECT * FROM `event` ";
        return baseDao.query(sql,Event.class);
    }
}

